package codingDudes.geom;

/**
 * This class provides storing of position data in 2D space as well as mathematical
 * methods.
 * 
 * @author Tobias Friese
 */

public class Point2D
{
	/* variables */
	public double x		= 0;
	public double y		= 0;
	
	/* constructors */
	public Point2D()
	{
		
	}
	
	public Point2D(double x, double y)
	{
		this.x = x;
		this.y = y;
	}
	
	/* math */
	public Point2D add(Point2D point)
	{
		return new Point2D(this.x + point.x, this.y + point.y);
	}
	
	public Point2D add(double x, double y)
	{
		return new Point2D(this.x + x, this.y + y);
	}
	
	public Point2D subtract(Point2D point)
	{
		return new Point2D(this.x - point.x, this.y - point.y);
	}
	
	public Point2D subtract(double x, double y)
	{
		return new Point2D(this.x - x, this.y - y);
	}
	
	public Point2D multiply(Point2D point)
	{
		return new Point2D(this.x * point.x, this.y * point.y);
	}
	
	public Point2D multiply(double x, double y)
	{
		return new Point2D(this.x * x, this.y * y);
	}
	
	public Point2D divide(Point2D point)
	{
		return new Point2D(this.x / point.x, this.y / point.y);
	}
	
	public Point2D divide(double x, double y)
	{
		return new Point2D(this.x / x, this.y / y);
	}
	
	public double distance(Point2D point)
	{
		return Math.sqrt(Math.pow((point.x - this.x), 2) + Math.pow((point.y - this.y), 2));
	}
	
	public double distance(double x, double y)
	{
		return Math.sqrt(Math.pow((x - this.x), 2) + Math.pow((y - this.y), 2));
	}
	
	public String toString()
	{
		return "[Point2D] x:" + this.x + " y:" + this.y;
	}
}
